<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class IndexTableModel extends Model
{
    /**
     * 查询列表(带分页)
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getListPage($tbale,$where,$field,$page,$nums,$order){
        $list = Db::table($tbale)->where($where)->field($field)->page($page,$nums)->order($order)->select();
        return $list;
    }

    /**
     * 查询列表(无分页)
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getList($tbale,$where,$field,$order){
        $list = Db::table($tbale)->where($where)->field($field)->order($order)->select();
        return $list;
    }

    /**
     * 查询列表(无分页,有缓存)
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getListCache($tbale,$where,$field,$order,$cachekey){
        $list = Db::table($tbale)->where($where)->field($field)->order($order)->cache($cachekey,10)->select();
        return $list;
    }

    /**
     * 查询列表(无分页,有缓存)
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getListCacheLimit($tbale,$where,$field,$order,$cachekey,$limit){
        $list = Db::table($tbale)->where($where)->field($field)->order($order)->cache($cachekey,10)->limit($limit)->select();
        return $list;
    }

    /**
     * 查询数量
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getTotal($tbale,$where,$count){
        $total = Db::table($tbale)->where($where)->count($count);
        return $total;
    }

    /**
     * 单个查询
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getFind($tbale,$where,$field){
        $info = Db::table($tbale)->where($where)->field($field)->find();
        return $info;
    }

    /**
     * 单个查询
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getFindOrder($tbale,$where,$field,$order){
        $info = Db::table($tbale)->where($where)->field($field)->order($order)->find();
        return $info;
    }

    /**
     * 单个添加
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function addInfo($tbale,$data){
        $res = Db::table($tbale)->insertGetId($data);
        return $res;
    }

    /**
     * 单个修改
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function editInfo($tbale,$where,$data){
        $res = Db::table($tbale)->where($where)->update($data);
        return $res;
    }

    /**
     * 真实删除
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function delOne($tbale,$where){
        $res = Db::table($tbale)->where($where)->delete();
        return $res;
    }

    /**
     * 查询总分数
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function getNum($tbale,$where,$sum){
        $total = Db::table($tbale)->where($where)->sum($sum);
        return $total;
    }

    /**
     * 字段+1
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function setIncNum($tbale,$where,$filed,$num){
        $res = Db::table($tbale)->where($where)->setInc($filed,$num);
        return  $res;
    }

    /**
     * 字段-1
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function setDecNum($tbale,$where,$filed,$num){
        $res = Db::table($tbale)->where($where)->setDec($filed,$num);
        return  $res;
    }

    /**
     * column方法
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function selColumn($tbale,$where,$filed){
        $res = Db::table($tbale)->where($where)->column($filed);
        return  $res;
    }

    /**
     * group
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function selGroup($tbale,$where,$filed,$group,$page,$nums,$order)
    {
        $res = Db::table($tbale)->where($where)->field($filed)->group($group)->page($page,$nums)->order($order)->select();
        return $res;
    }

    /**
     * group count
     * User:@hang
     * Date:2024-03-30 12:06
     */
    public function countGroup($tbale,$where,$group,$count)
    {
        $res = Db::table($tbale)->where($where)->group($group)->count($count);
        return $res;
    }
}